﻿using System;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Specialized;

namespace spSiteNewsView.Layouts.spSiteNewsView
{
    public partial class NewsView : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            NameValueCollection query = Request.QueryString;
            //--
            Uri rUrl = Request.UrlReferrer;
            b2.PostBackUrl = rUrl.AbsoluteUri;
            //--
            string sSite = query["site"];
            string sWeb = query["web"];
            string sList = query["list"];
            string sID = query["id"];

            string sTitle = query["title"];
            string sRem = query["rem"];
            //--
            SPSite site = new SPSite(sSite);
            SPWeb mWeb = site.OpenWeb(sWeb);
            try
            {
                SPList list = mWeb.Lists[sList];
                foreach (SPListItem item in list.Items)
                {
                    if (item.ID.ToString() == sID)
                    {
                        lHeader.Text = item[sTitle].ToString();
                        if (item[sRem] != null)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(item[sRem].ToString());
                            lList.Text = sb.ToString();
                        }
                        SPAttachmentCollection aColl = item.Attachments;
                        if (aColl != null)
                        {
                            for (int i = 0; i < aColl.Count; i++)
                            {
                                Img2.ImageUrl = aColl.UrlPrefix + aColl[i];
                            }
                        }
                    }
                }
            }
            catch
            { 
            }
        }
    }
}
